package com.hxzy.controller;

import com.hxzy.common.annon.RequiresPermissions;
import com.hxzy.common.consts.RedisConst;
import com.hxzy.common.enums.AckCode;
import com.hxzy.common.security.AdminInfoUtil;
import com.hxzy.common.vo.PageVO;
import com.hxzy.common.vo.R;
import com.hxzy.common.web.controller.BaseController;
import com.hxzy.service.SysUserService;
import com.hxzy.system.dto.AdminLoginDTO;
import com.hxzy.system.dto.SysUserDTO;
import com.hxzy.system.vo.AdminLoginVO;
import com.hxzy.system.vo.SysMenuVO;
import com.hxzy.system.vo.SysUserVO;
import com.hxzy.system.vo.router.RouterVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Api(tags = "后台用户API")
@RestController
@RequestMapping(value = "/user")
public class SysUserController extends ExistsValueController {

    @Autowired
    private SysUserService sysUserService;


    @RequiresPermissions(value = "system:user:list")
    @ApiOperation("用户信息分页")
    @GetMapping(value = "/data")
    public R<PageVO> search(SysUserDTO sysUserDTO){
        super.startPageHelper();
        List<SysUserVO> page = this.sysUserService.search(sysUserDTO);
        return super.pageToPageVO(page);
    }

    @ApiOperation(value = "根据用户名查询信息")
    @GetMapping(value = "/byname/{username}")
    public R<SysUserVO> findUserByName(@PathVariable(value = "username") String username){
        SysUserVO userByName = this.sysUserService.findUserByName(username);
        return userByName==null? R.build(AckCode.NOT_FOUND_DATA): R.okHasData(userByName);
    }




}
